/************************************************************************/
/*                                                                      */
/************************************************************************/
#pragma once

#include <GL/glew.h>

#include <QGLWidget>
#include <QKeyEvent>
#include <QMouseEvent>

#include "math/mtxlib.h"
#include "math/Matrix4.h"
#include <glut.h>

namespace PBVP {
	class MainInterface;
	class MainWindow;
	class Environment;
	/// <summary>
	/// 
	/// </summary>
	class ZGLWidget : public QGLWidget {
		Q_OBJECT
	public:
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="parent"></param>
		ZGLWidget(MainInterface *pMainInterface, MainWindow *parent);
		/// <summary>
		/// Destructor
		/// </summary>
		~ZGLWidget(void);

		/// Reset transformation matrix to identity matrix	
		void resetTransform() {
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			transMtx = TranslateMatrix44(0, 0, -4); 
			rotMtx.identity();
			updateGL();
		}

		/// Enter full-screen display
		/**
		 *
		 */
		void viewFullScreen();
		/// Leaver full-screen mode
		void endFullScreen();

		/// 
		bool isFullScreen() {
			return m_FullScreen;
		}
	public slots:
		void showBBox(bool visible);

	protected:
		virtual void initializeGL();
		virtual void resizeGL(int, int);
		virtual void paintGL();
		virtual void keyPressEvent(QKeyEvent *e);
		virtual void mousePressEvent(QMouseEvent *e);
		virtual void mouseMoveEvent(QMouseEvent *e);

		Qt::MouseButton button;				// current button pressed
		int mouseXY[2];						// x and y coordiantes of mouse pointer
		matrix44 rotMtx, transMtx;			// rotation and translation matrices
		Matrix4 m_Translation;
		Quaternion m_Rotation;
		float fov;							// field of view angle
		float m_near, m_far;				// near and far plane
		float rotFactor, transFactor;		// factors of ratation and translation speed

		Environment& m_Env;
		MainInterface *m_pMainInterface;
		/// Parent Widget
		MainWindow *m_pParent;
		/// full screen flag
		bool m_FullScreen;
		/// show or hide bounding box
		bool m_ShowBBox;
	};
}

